import request from './request'

export const homeworkApi = {
  // 创建作业
  create(data) {
    return request.post('/homework', data)
  },

  // 更新作业
  update(id, data) {
    return request.put(`/homework/${id}`, data)
  },

  // 删除作业
  delete(id) {
    return request.delete(`/homework/${id}`)
  },

  // 获取当前作业（最早的）
  getCurrent(studentId) {
    return request.get('/homework/current', { params: { studentId } })
  },

  // 获取所有当前作业
  getAllCurrent(studentId) {
    return request.get('/homework/current/all', { params: { studentId } })
  },

  // 开始作业
  start(id) {
    return request.post(`/homework/${id}/start`)
  },

  // 完成作业项
  completeDetail(detailId) {
    return request.post(`/homework/detail/${detailId}/complete`)
  },

  // 获取作业明细
  getDetails(id) {
    return request.get(`/homework/${id}/details`)
  },

  // 动态添加作业项
  addDetail(homeworkId, detailData) {
    return request.post(`/homework/${homeworkId}/detail`, detailData)
  },

  // 删除未完成作业项
  deleteDetail(homeworkId, detailId) {
    return request.delete(`/homework/${homeworkId}/detail/${detailId}`)
  },

  // 修改作业项内容
  updateDetail(homeworkId, detailId, detailData) {
    return request.put(`/homework/${homeworkId}/detail/${detailId}`, detailData)
  },

  // 调整作业项必须/非必须属性
  updateDetailRequired(homeworkId, detailId, isRequired) {
    return request.put(`/homework/${homeworkId}/detail/${detailId}/required`, { isRequired })
  }
}